using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Deepcode.Flux.Core.Data;
using Deepcode.Flux.Core.Services.State;
using Deepcode.Flux.Core.Systems.Audit.Quick;
using Deepcode.Flux.Core.Systems.Workflow.Bases;

public partial class Private_Config_Workflow_ui_Handlers : Deepcode.Flux.Core.UI.AdministrationModulePage
{
	#region Permission Code Override
	public override string RequiredPermissionCode { get { return "FluxWorkflowEdit"; } }
	#endregion
	#region Page Load event
	/// <summary>
	/// Page Load event
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
			BindDataGrid();
		}
	}
	#endregion
	#region Initialisation
	/// <summary>
	/// OnInit - hooks up the data paging handler, 
	/// rpp change handler and item command handlers
	/// </summary>
	/// <param name="e"></param>
	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
		datagrid.ItemCommand += new DataGridCommandEventHandler(GridCommand);
	}
	#endregion
	#region Data binding and paging events
	/// <summary>
	/// Data binding
	/// </summary>
	private void BindDataGrid()
	{
		// Get and bind the data
		Handlers handlers = new Handlers();
		datagrid.DataSource = handlers.GetAllHandlers();
		datagrid.DataBind();
	}
	#endregion
	#region User interactions
	/// <summary>
	/// Command received from the data grid
	/// </summary>
	/// <param name="source"></param>
	/// <param name="e"></param>
	void GridCommand(object source, DataGridCommandEventArgs e)
	{
		if( e.Item.ItemType == ListItemType.Footer ||
			e.Item.ItemType == ListItemType.Header ||
			e.Item.ItemType == ListItemType.Pager ||
			e.Item.ItemType == ListItemType.Separator ) return;

		// Get the key of the row being actioned 
		string rowHandlerID = (string) datagrid.DataKeys[e.Item.ItemIndex];

		// PROCESS COMMANDS
		if( e.CommandName == "Definitions" )
		{
			string url = String.Format("ui_Definitions.aspx?HandlerID={0}", rowHandlerID);
			Response.Redirect( url, true );
			return;
		}
	}
	#endregion
}
